import { getContractData, getContractDetails, contractAddSave, submit, contractRemove, contractShow, getPaymentType } from '@/api/contract'
export default {
  namespaced: true, // 封闭
  state: {},
  mutations: {},
  getters: {},
  actions: {
    // 获取合同管理数据
    async fetchContractData(context, payload) {
      const { status, perPage, page } = payload
      try {
        const { data } = await getContractData(status, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 续签之前先获取详情
    async fetchContractDetails(context, payload) {
      const { renewContractId } = payload
      try {
        const { data } = await getContractDetails(renewContractId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 保存 新增 或者 续签 合同
    async fetchContractAddSave(context, payload) {
      try {
        const { data } = await contractAddSave(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 提交合同
    async submit(context, payload) {
      const { renewContractId, signDate, months, dueTime, businessId, businessName, stallName, contractAmount, contractNumber, contractPhoto } = payload
      try {
        const { data } = await submit(renewContractId, signDate, months, dueTime, businessId, businessName, stallName, contractAmount, contractNumber, contractPhoto)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 点击合同解除
    async contractRemove(context, payload) {
      const { contractId, status } = payload
      try {
        const { data } = await contractRemove(contractId, status)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 点击合同续签
    async contractShow(context, payload) {
      const { contractId } = payload
      try {
        const { data } = await contractShow(contractId)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 获取 收费项目 类型
    async fetchPaymentType(context, payload) {
      const { searchName } = payload
      try {
        const { data } = await getPaymentType(searchName)
        return data
      } catch (err) {
        console.log(err)
      }
    }
  }
}
